package com.ujiuye.web;



import com.fasterxml.jackson.databind.ObjectMapper;
import com.ujiuye.entity.KeyWord;
import com.ujiuye.service.KeyWordService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
@WebServlet("/search")
public class SearchServlet<Keyword> extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        //获取参数
        String name=req.getParameter("name");
        KeyWordService ks=new KeyWordService();
        List<KeyWord> list=ks.queryWord(name);
        //解析list
        ObjectMapper om = new ObjectMapper();
        String json = om.writeValueAsString(list);
        System.out.println(json);
        //响应
        resp.getWriter().println(json);
    }
}
